<template>
    <PageWrapper>
      <n-card :bordered="false" class="mb-3 proCard">
        <n-space align="center">
          <n-input-group style="width: 1280px">
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-input
                style="width: 100%;margin-left: 20px;"
                v-model:value="params.user_id"
                clearable
                placeholder="请输入用户id"
                @keyup.enter="reloadTable"
                />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-input
                style="width: 100%;margin-left: 20px;"
                v-model:value="params.danhao"
                clearable
                placeholder="请输入付款编号"
                @keyup.enter="reloadTable"
                />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-select v-model:value="params.pt_attr" placeholder="请选择程序类型" style="width: 200px;margin-left: 20px;" :options="options" clearable />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-select v-model:value="params.leixing" placeholder="请选择充值类型" style="width: 200px;margin-left: 20px;" :options="optionleixing" clearable />
            </div>
            <div style="margin-left: 30px !important;display: flex;align-items: center;">
              <n-date-picker v-model:value="range" type="daterange"  @update:value="onChange4" clearable />
            </div>
            <n-button type="primary" style="margin-left: 40px !important;" @click="reloadTable">
              <template #icon>
                <n-icon>
                  <SearchOutlined />
                </n-icon>
              </template>
              查询
            </n-button>
          </n-input-group>
        </n-space>
        <div class="wenzi">
          <span class="shouyi">总充值:</span><span class="money">{{rechargerData.zczmoney}}元</span>
          <span class="yue">总赠送:</span><span class="money">{{rechargerData.zzsmoney}}元</span>
        </div>
      </n-card>
      <n-card :bordered="false" class="proCard">
        <BasicTable
          :columns="columns"
          :request="loadDataTable"
          :row-key="(row) => row.id"
          ref="basicTableRef"
          virtual-scroll
        >
        </BasicTable>
      </n-card>

    </PageWrapper>
  </template>
  
  <script lang="ts" setup>
    import { reactive, ref, onMounted } from 'vue';
    import { BasicTable } from '@/components/Table';
    import { SearchOutlined } from '@vicons/antd';
    import { columns } from './columns';
    import { rechargerecordlist,rechargerdata } from '@/api/financial/index';
  
    const basicTableRef = ref();
    const tableData = ref();
    const range = ref<[number, number]>();
  
    const params = reactive({
      user_id: '',
      danhao: '',
      pt_attr: null,
      leixing: null,
      sdate: '',
      edate: '',
    });

    const rechargerData = ref({
      zczmoney: 0,
      zzsmoney: 0,
    });

    const options = ref([
      {
        label: "微信小程序",
        value: 1,
      },
      {
        label: '抖音小程序',
        value: 2
      },
      {
        label: '支付宝小程序',
        value: 3
      }
    ])

    const optionleixing = ref([
      {
        label: "单次充值",
        value: 0,
      }, {
        label: '充值套餐',
        value: 1
      }, {
        label: '后台充值',
        value: 3
      }
    ])

    //列表数据
    const loadDataTable = async (res) => {
      const result = await rechargerecordlist({ ...params, ...res });
      tableData.value = result.list;
      return result;
    };

    //加载表格
    function reloadTable() {
      basicTableRef.value.reload();

      rechargerdata({ ...params }).then((res) => {
        rechargerData.value = res;
      });
    }

    function onChange4(v: number){
      if(v != null){
        params.sdate = v[0];
        params.edate = v[1];
      }else{
        params.sdate = '';
        params.edate = '';
      }
    }

    onMounted(async () => {
      const res1 = await rechargerdata({ ...params });
      rechargerData.value = res1
    });
  
  </script>
  
  <style lang="less" scoped>
    .wenzi{
      margin-top: 20px;
      margin-left: 2%;
      font-size: 18px;

      .shouyi{
        margin-right: 10px;
      }

      .yue{
        margin-left: 30px;
        margin-right: 10px;
      }

      .money{
        color: red;
        font-weight: 700;
      }
    }
  </style>
  